﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;

namespace LiteratureManage.Web.Controllers
{
    using LiteratureManage.Web.ViewModels;

    public partial class AccountController : BaseController
    {
        public virtual ActionResult SignIn()
        {
            return View();
        }

        [HttpPost]
        public virtual ActionResult SignIn(SignInViewModel model)
        {
            return CheckValidCall(() =>
            {
                if (FormsAuthentication.Authenticate(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, false);
                }
            })
            .Valid(()=> Redirect(String.IsNullOrEmpty(model.ReturnUrl) ? FormsAuthentication.DefaultUrl : model.ReturnUrl))
            .Invalid(()=> View(model));
        }

        public virtual ActionResult SignOut()
        {
            FormsAuthentication.SignOut();

            return RedirectToAction(MVC.Home.Index());
        }
    }
}
